import time
import jwt

# 个人服务器私钥
private_key = "MC4CAQAwBQYDK2VwBCIEIDHTYK6EPli6vlMIT06pbuHMZWd/FVrUYLIU1jnozCAs"

# 凭据ID
kid_KWY = "CNPKEJ3CVW"

# 项目ID
project_id = "2FTJY789G8"

def getJWT() -> str:
    # 将PKCS#8格式转换为PEM格式
    private_key_pem = f"""-----BEGIN PRIVATE KEY-----
                        {private_key}
                        -----END PRIVATE KEY-----"""
    # JWT载荷和头部
    payload = {
        'iat': int(time.time()) - 30,
        'exp': int(time.time()) + 900,
        'sub': f'{project_id}'
    }
    headers = {
        'kid': f'{kid_KWY}'
    }

    # 生成JWT
    encoded_jwt = jwt.encode(payload, private_key_pem, algorithm='EdDSA', headers=headers)
    # print(f"✅ JWT生成成功!")
    return encoded_jwt